package cn.ant.schedule;

import cn.ant.annotation.AopTimerLog;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @Version 1.0
 * @Author:lss
 * @Date:2021/10/18
 * @Content:
 */
@Component
@Slf4j

public class XXLJobTest {

    @Autowired
    private XXLJobTest xxlJobTest;
    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello World.");
        CompletableFuture.runAsync(()->{
           xxlJobTest.test();
        });

        // default success
    }
    @AopTimerLog
    public void test() {
        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            log.info("beat at:" + i);
//            TimeUnit.SECONDS.sleep(2);
        }
    }
}
